package components;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.JButton;


import listeners.LoginActionListener;
import javax.swing.SwingConstants;

public class AuthenticationContentPanel extends JPanel
{

	private static final long serialVersionUID = 1L;
	private JLabel usernameLabel;
	private JLabel passwordLabel;
	private JButton loginButton;
	private JTextField usernameTextField;
	private JPasswordField passwordTextField;
	private JLabel statusLabel;
	
	public AuthenticationContentPanel()
	{
		this.buildComponents();
	}
	private void buildComponents()
	{
		loginButton = new JButton("Login");
		loginButton.setBounds(204, 127, 102, 23);
		passwordTextField = new JPasswordField(20);
		passwordTextField.setBounds(192, 67, 166, 20);
		passwordLabel = new JLabel("Password");
		passwordLabel.setBounds(117, 70, 71, 14);
		usernameLabel = new JLabel("Username");
		usernameLabel.setBounds(115, 39, 73, 14);
		usernameTextField = new JTextField(20);
		usernameTextField.setBounds(192, 36, 166, 20);
		setLayout(null);
		statusLabel = new JLabel();
		statusLabel.setHorizontalAlignment(SwingConstants.CENTER);
		statusLabel.setBounds(12, 99, 476, 16);
		
		add(statusLabel);
		add(loginButton);
		add(passwordTextField);
		add(passwordLabel);
		add(usernameLabel);
		add(usernameTextField);
		
		addListeners();
	}
	public String getUsername()
	{
		return usernameTextField.getText();
	}
	public String getPassword()
	{
		return new String(passwordTextField.getPassword());
	}
	public void setStatusText(String text)
	{
		this.statusLabel.setText(text);
	}
	private void addListeners()
	{
		LoginActionListener loginListener = new LoginActionListener(this);
		
		loginButton.addActionListener(loginListener);
		usernameTextField.addActionListener(loginListener);
		passwordTextField.addActionListener(loginListener);
	}
}
